package com.gitee.wsl.ext.list

import kotlin.math.min


fun <T> List<T>.splitByIndices(startIndices: Sequence<Int>): Sequence<List<T>> {
    return (startIndices + size).zipWithNext { start, endExclusive ->
        subList(start, endExclusive)
    }
}

fun <T> MutableList<T>.split(partSize: Int): List<MutableList<T>> {
    val s = size
    if (s <= partSize) {
        return listOf(this)
    }

    val parts = (s + partSize - 1) / partSize
    val res = (0 until parts).map { subList(it * partSize, min((it + 1) * partSize, s)) }
    return res
}